fix: installer failing on opencode.jsonc files with trailing commas#49
Merged
Conversation
b9d0953 to
b81e546
Compare
The auto-generated opencode.jsonc often contains trailing commas, which is valid JSONC but rejected by JSON.parse. This caused the one-liner installer to fail for many users without a clear path to recovery. The fix adds a string-context-aware trailing comma stripper that runs after comment removal, before JSON.parse. The logic is extracted into a typed module (src/jsonc.ts) so it can be unit tested independently from the self-contained bash script that inlines it.
Array indexing returns number | undefined under strict TS config; use a non-null assertion where the valid index is guaranteed by the test setup.
b81e546 to
6a411d0
Compare
There was a problem hiding this comment.
Pull request overview
Fixes the one-liner installer failing when opencode.jsonc contains JSONC-valid trailing commas by stripping trailing commas (string-aware) after comment removal and before JSON.parse.
Changes:
- Add
src/jsonc.tswithscan()(comment stripper + index map) andremoveTrailingCommas()(string-aware trailing comma remover). - Add a comprehensive
vitestsuite covering both helpers and the end-to-end parsing pipeline (scan → removeTrailingCommas → JSON.parse), including a real-world reproduction. - Update
install.shto applyremoveTrailingCommas()to the comment-stripped JSON before parsing, and document that the JS in the installer is a copy ofsrc/jsonc.ts.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/jsonc.test.ts | Adds unit + pipeline tests for comment stripping and trailing-comma removal, including bug reproduction. |
| src/jsonc.ts | Introduces typed JSONC utilities (scan, removeTrailingCommas) intended to stay in sync with installer logic. |
| install.sh | Applies trailing-comma stripping before JSON.parse so JSONC configs with trailing commas no longer break installation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
justin-carper
approved these changes
Jun 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The auto-generated opencode.jsonc often contains trailing commas, which is valid JSONC but rejected by
JSON.parse. This caused the one-liner installer to fail for many users without a clear path to recovery.The fix adds a string-context-aware trailing comma stripper that runs after comment removal, before
JSON.parse. Commas inside string values are never touched — only true trailing commas (those immediately before a closing]or}) are removed.The logic is extracted into a typed module (
src/jsonc.ts) so it can be unit tested independently from the self-contained bash script that inlines it. The test suite covers the full parsing pipeline, including a reproduction of the exact input shape from the bug report.